package com.apes.hr.base.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * 功能：人员家庭成员
 * @author HuJianlin
 * @create 2018-04-25 15:11
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = EmployeeFamily.CONST_TABLE_NAME)
public class EmployeeFamily  extends Model {
    public static final String CONST_TABLE_NAME = "hr_Employee_Family";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "人员家庭成员")
    @Comment("家庭成员编码")
    private long id; //家庭成员编码

    @ManyToOne
    @JoinColumn(name = "employee_id", referencedColumnName="id")
    @Comment("员工")
    private Employee employee; //员工

    @ManyToOne
    @JoinColumn(name = "talent_pool_id", referencedColumnName="id")
    @Comment("人才储备")
    private TalentPool talentPool; //人才储备

    @Name
    @Column(name = "name", nullable = false, length = 16)
    @Comment("姓名")
    private String name; //姓名

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "relation_id", referencedColumnName = "id")
    @Comment("关系")
    private Enumeration relation; //关系(FamilyRelation)

    @Column(name = "age")
    @Comment("年龄")
    private int age;  //年龄

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "birthday")
    @Comment("生日")
    private Date birthday; //生日

    @Column(name = "work_unit", length = 32)
    @Comment("工作单位")
    private String workUnit; //工作单位

    @Column(name = "jobs",  length = 16)
    @Comment("职务")
    private String jobs; //职务

    @Column(name = "mobile_number", length = 16)
    @Comment("手机号")
    private String mobileNumber; //手机号

    @Column(name = "entry_info_id", length = 16)
    @Comment("入职资料补充单号")
    private String entryInfoId;
}
